import { createRouter, createWebHashHistory } from 'vue-router'

// 路由懒加载，按需引入
const Layout = () => import('@/views/Layout')
const HomePage = () => import('@/views/home/index')
// 一级路由组件与二级路由组件的注册  与home同为二级路由
const Categorylist = () => import('@/views/category/index')
const sub = () => import('@/views/category/sub')
const Goods = () => import('@/views/goods/index')
const Login = () => import('@/views/login/index')
const callBack = () => import('@/views/login/callBack')
const XtxCartPage = () => import('@/views/cart/index')
const routes = [
  // 一级路由布局容器
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/',component: HomePage },
      // 一级路由与二级路由注册
      { path: '/category/:id',component:Categorylist},
      { path: '/category/sub/:id',component:sub},
      { path: '/product/:id', component:Goods},
      { path: '/cart',component:XtxCartPage}
    ]
  },
  {
    path:'/login',
    component:Login,
  },
  {
    path:'/login/callBack',
    component:callBack
  }
]
// vue3创建路由实例
const router = createRouter({
  // 使用hash的路由实例
  history: createWebHashHistory(),
  routes,
  // 滚动到页面顶部
  scrollBehavior(){
    return { left: 0, top: 0 }
  }
})
export default router
